#!/usr/bin/python
# -*- coding: utf-8 -*-
import cgi
import memcache

# Accept events.
el = ['up', 'down', 'left', 'right']

# connect to memcache server
mc = memcache.Client(['127.0.0.1:11211'])

# get user parameter.
f = cgi.FieldStorage()
event = f.getfirst('event') or ''

# verify parameter & if accept-event, put into memcached.
if (event in el):
    mc.set('iphone_event', event)
    out = 'Accepted event: '+event
else:
    out = 'Denied event:'+event

# Output
print "Content-Type: text/plain"
print
print out
